# @Time    :2025/3/27 20:36
### 编程题 2：嵌套字典数据处理
"""
有一个嵌套字典，存储了学生的课程成绩信息。 编写一个函数，计算每个学生的平均成绩，
并返回一个新的字典，键为学生名字，值为平均成绩。
结构如下：
students = {
    "Alice": {
        "Math": 85,
        "English": 90,
        "Science": 78
    },
    "Bob": {
        "Math": 92,
        "English": 88,
        "Science": 95
    },
    "Charlie": {
        "Math": 70,
        "English": 75,
        "Science": 80
    }
}
"""
students = {
    "Alice": {
        "Math": 85,
        "English": 90,
        "Science": 78
    },
    "Bob": {
        "Math": 92,
        "English": 88,
        "Science": 95
    },
    "Charlie": {
        "Math": 70,
        "English": 75,
        "Science": 80
    }
}


# def stu_score(students):
#     pj_score = {}  # 定义一个字典，用来存储 计算后新的字典
#     for k, v in students.items():
#         # pj = sum(v.values()) / len(v)  # 平均分
#         # pj_score[k] = round(pj, 2)  # 处理平均分
#           pj_score[k] = sum(v.values()) // len(v)  # 平均分 用// 就不用小数点处理
#     return pj_score
#
#
# print(stu_score(students))


def average(d1):
    dict1 = {}
    for i,j in d1.items():
        #(m for n,m in j.items())

        dict1[i] = round(((sum(m for n,m in j.items()))/len(j)),2)
    return dict1
print(average(students))


def av(d1):
    new_list = {}
    for k,v in students.items():
        list1 = [m for n,m in v.items()]
        average = sum(list1)/len(list1)
        average = round(average,2)
        new_list[k] = average
    return new_list

#
# def stu_score(students):
#     pj_score = {}  # 定义一个字典，用来存储 计算后新的字典
#     for k, v in students.items():
#         print(v.values())
#         count = 0
#         for i in v.values():
#             count += i
#             n = count // len(v.values())
#             pj_score[k] = n
#
#     return pj_score
#
#
# print(stu_score(students))
